package idao;

import idao.engine.IDAOImpl;

import javax.sql.DataSource;

/**
 * Responsible for creating instances of IDAO.
 * 
 * @author huhao
 */
public class IDAOFactory
{

    private IDAOFactory()
    {
        // No instantiation needed.
    }

    /**
     * Creates an new IDAO using the given {@link DataSource}.
     * 
     * @param ds
     *        the {@link DataSource} used to get {@link java.sql.Connection}
     * @return an IDAO instance
     * @throws NullPointerException
     *         if the given data source object is {@code null}
     */
    public static IDAO newIDAO(DataSource ds)
    {
        return new IDAOImpl(ds);
    }

    /**
     * Creates an new IDAO using the given {@link ConnectionManager}.
     * 
     * @param ds
     *        the {@link Connection} used to get {@link java.sql.Connection}
     * @return an IDAO instance
     * @throws NullPointerException
     *         if the given connection manager is {@code null}
     */
    public static IDAO newIDAO(ConnectionManager cm)
    {
        return new IDAOImpl(cm);
    }
}
